import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path' // 添加 path 模块导入

// https://vite.dev/config/
export default defineConfig({

  plugins: [vue()],
  resolve: {
    alias: {
      // 正确配置路径别名
      '@': path.resolve(__dirname, 'src') // 通常指向 src 目录
    }
  },
  "compilerOptions": {
    "types": [
      "vite/client",
      "pinia-plugin-persistedstate" // 新增类型声明
    ]
  },
  server: {
    watch: {
      ignored: ['**/image/**'] // 忽略上传目录
    },
    proxy: {
      '/api': {
        target: 'http://localhost:8080',
        changeOrigin: true,
        
      },
    },
  },
  css: {
    loaderOptions: {
      scss: {
        additionalData: `@import "@/styles/variables.scss";`
      }
    }
  },
  build: {
    assetsInclude: ['**/*.woff', '**/*.ttf'], // 确保包含字体文件
    rollupOptions: {
      output: {
        //assetFileNames: 'assets/[name].[hash].[ext]', // 保留字体扩展名
        assetFileNames: (assetInfo) => {
          const extType = assetInfo.name?.split('.').at(1)
          if (/woff|ttf/i.test(extType)) {
            return `assets/fonts/[name].[hash][extname]`
          }
          return `assets/[name].[hash][extname]`
        }
      }
    },
    index: path.resolve(__dirname, '../dist/index.html'),
    assetsRoot: path.resolve(__dirname, '../dist'),
    assetsSubDirectory: 'static',
    assetsPublicPath: './',
  },
  //静态资源服务的文件夹
  publicDir: "public",
  base: './',
  publicPath: './', // 关键配置：使用相对路径
  outputDir: 'dist',
  assetsDir: 'static',
  productionSourceMap: false
})